package com.cube.reactive.guide.reactive;

import reactor.core.publisher.Flux;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

/**
 * @author litb
 * @since 2024/6/13 17:28
 */
public class SubscribeOn {


    public static void main(String[] args) {

        Scheduler s = Schedulers.newParallel("subscribe-scheduler", 4);
        Scheduler d = Schedulers.newParallel("publish-scheduler", 4);

        final Flux<String> flux = Flux
                .range(1, 2)
                .map(i -> 10 + i)
                .publishOn(d)
                .subscribeOn(s)
                .map(i -> "value " + i);

        new Thread(() -> flux.subscribe(v -> {
            System.out.println(Thread.currentThread().getName() + " " + v);
        })).start();
    }
}
